﻿using Contract.Infrastructure.Repository;
using Contract.WebApi.Application.Commands;
using MediatR;

namespace Contract.WebApi.Application.CommandHandler
{
    public class DelsHZContractCommandHandler : IRequestHandler<DelsHZContractCommands, int>
    {
        private readonly IRepository<Domain.Contract> repository;

        public DelsHZContractCommandHandler(IRepository<Domain.Contract> repository)
        {
            this.repository = repository;
        }

        public async Task<int> Handle(DelsHZContractCommands request, CancellationToken cancellationToken)
        {
            int ind = 0;
            foreach(var i in request.Ids)
            {
                var info = await repository.GetAsync(i);
                info.IsDel = true;
                info.UpdateDate = DateTime.Now;
                ind += await repository.UpdateAsync(info);
            }
            return ind;
        }
    }
}
